<%--
  Created by IntelliJ IDEA.
  User: lixiaodong
  Date: 2018/4/8
  Time: 15:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div id="role_dialog" class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center'">
        <table id="role_user_dg" data-options="fit:true,border:false"></table>
    </div>
    <div data-options="region:'south'" style="height: 50px;padding-top: 10px;">
        <div style="position: absolute; right: 20px">
            <a href="javascript:;" id="role_add_ok" class="easyui-linkbutton" data-options="iconCls:'fa fa-check'" style="margin-right: 10px">确 定</a>
            <a href="javascript:;" id="role_add_cancel" class="easyui-linkbutton" data-options="iconCls:'fa fa-times'">关 闭</a>
        </div>
    </div>
</div>

<script type="text/javascript">
    _role_user_js = {
        _qp:null,
        datagrid_init:function (_queryParams) {
            _role_user_js._qp = $('#role_dialog').dialog('options').queryParams;
            var _columns = [[
                {field:'id',title:'ID',width:0,hidden:'true'},
                {field:'person',title:'person',width:0,hidden:'true'},
                {field:'userName',title:'用户名',width:100},
                {field:'person_name',title:'姓名',width:200,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.phone==null?"":row.person.phone);
                        }
                        return "未指定";
                    }},
                {field:'person_phone',title:'电话',width:200,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.phone==null?"":row.person.phone);
                        }
                        return "未指定";
                    }},
                {field:'person_qq',title:'QQ',width:200,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.qq==null?"":row.person.qq);
                        }
                        return "未指定";
                    }},
                {field:'person_email',title:'邮箱',width:200,formatter: function(value,row,index){
                        if (row.person != null){
                            return (row.person.email==null?"":row.person.email);
                        }
                        return "未指定";
                    }},
                {field:'state',title:'状态',width:100},
            ]];
            var _url = bs.base_url + 'user/getAll.action';
            //bs.datagrid_load('role_user_dg',_columns,_url,null,_queryParams);
            $('#role_user_dg').datagrid({
                singleSelect:false,
                pagination:false,
                url: _url,
                columns: _columns,
                queryParams:_queryParams,
                idField: 'id',
                selectOnCheck: false,
                checkOnSelect: false,
                striped: true,
                autoRowHeight:false,
                nowrap:true,
                fit:true,
                resizable:false,
                loadMsg: false,
                rownumbers: true,
                onLoadSuccess:function (row, data) {
                    $.ajax({
                        url:bs.base_url + 'role/getUsers.action?id=' + _role_user_js._qp.row.id,
                        type:'post',
                        async:false,
                        dataTyoe:'json',
                        success:function (data) {
                            var result = JSON.parse(data);
                            for (var i = 0; i < result.length; i++){
                                $('#role_user_dg').datagrid('selectRecord',result[i].id);
                            }
                        }
                    });
                }
            });
        },
        btn_init:function () {
            $('#role_add_ok').on('click', function () {
                var _rows = $('#role_user_dg').treegrid('getSelections');
                var _value = '';
                if (_rows != null) {
                    for (var i = 0; i < _rows.length; i++) {
                        _value += _rows[i].id + '▁';
                    }
                }
                var _url = bs.base_url + 'role/setUsers.action?id=' + _role_user_js._qp.row.id + '&userIds=' + _value.substring(0, _value.length - 1);
                $.ajax({
                    url: _url,
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        //var result = JSON.parse(data);
                        if (data[0].status == 'success') {
                            $.messager.alert('成功', data[0].description);
                            $("#role_dialog").dialog('destroy');
                        } else {
                            $.messager.alert('失败', data[0].description);
                        }
                    }, error: function () {
                        $.messager.alert('警告', '请求失败，请检查网络连接');
                    }
                });
            });
            $('#role_add_cancel').on('click', function () {
                $("#role_dialog").dialog('destroy');
            });
        }
    }

    role_user_app = (function () {
        $(function () {
            _role_user_js.datagrid_+init(null);
            _role_user_js.btn_init();
        });
    })();
</script>